package com.mingnew.ecache.exception;

import com.mingnew.ecache.util.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : lk
 * @date 2021/5/2 12:06
 **/
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(RuntimeException.class)
    public Result runTimeException(RuntimeException ex) {
        return  Result.failed(HttpStatus.INTERNAL_SERVER_ERROR.value(),ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result exception(Exception ex) {
        return  Result.failed(HttpStatus.INTERNAL_SERVER_ERROR.value(),ex.getCause().getMessage());
    }

}
